<template>
    <div>
        <h3>会员等级修改</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">会员等级名称</td>
                    <td>
                        <input type="text" v-model="queryInfo.LevelName">
                    </td>
                </tr>
                <tr>
                    <td align="right">累计消费金额</td>
                    <td>
                        <input type="text" v-model="queryInfo.Money">
                    </td>
                </tr>
                <tr>
                    <td align="right">等级权益</td>
                    <td>
                        <select v-model="queryInfo.LevelRights" multiple size="10">
                                <option value="">请选择</option>
                                <option :value="item.RightName" v-for="item in data.list">{{ item.RightName }}</option>
                        </select>
                    </td>
                </tr>

                <tr>
                    <td></td>
                    <td>
                        <input type="button" @click="ok" class="btn btn-priamry" value="修改">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <!-- 考试完毕 -->
</template>

<script setup lang="ts">

import axios from 'axios';
import { ref, reactive, onMounted } from 'vue';
import { useRouter,useRoute } from 'vue-router';
const router = useRouter();
const route=useRoute();
let queryInfo:any = reactive({
    "Id":route.query.id,
    "LevelName": "",
    "Money": "",
  "LevelRights": [],
})
let data:any=reactive({
    list:[]
})
onMounted(()=>{
    getList()
    egtDate();
})
const egtDate=()=>{
    axios({
        method:"get",
        url:"/api/Member/UpdateMemberLevle",
        params:{
            id:route.query.id
        }
    })
    .then(res=>{
        console.log(res)
        Object.assign(queryInfo,res.data);
        queryInfo.LevelRights=res.data.LevelRights
    })
    .catch(err=>{
        console.log(err);
    })
}


//获取权益列表
const getList=()=>{
    axios({
        method:"get",
        url:"/api/Member/GetRightModelsList"
    })
    .then(res=>{
        console.log(res);
        data.list=res.data
    })
}


const ok = () => {
    queryInfo.LevelRights=queryInfo.LevelRights.toString();
    //1.判断有效性
    if (queryInfo.LevelName == "") {
        alert('等级名称不能为空');
        return;
    }
    console.log(queryInfo);
    //2.发送请求
    axios({
        method: 'post',
        url: '/api/Member/UpdateMemberLevelOk',
        data: queryInfo,
    })
        .then(res => {
            if (res.data > 0) {
                alert('修改成功');
                router.push('/MemberLevelList');
            }
            else if (res.data == -1) {
                alert('等级名称重复')
            }
        })
        .catch(err => {
            console.log(err);
        })

}


</script>




<style scoped></style>